﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using System.Dynamic;
using System.Collections.Generic;
namespace CommonUnitTest
{
    [TestClass]
    public class UnitTest1
    {
        #region JsonHelperTest
        [TestMethod]
        public void ArryJson2ListTest()
        {
            string json = @"[{
                'Title': 'Json.NET is awesome!',
                'Author': {
                  'Name': 'James Newton-King',
                  'Twitter': '@JamesNK',
                  'Picture': '/jamesnk.png'
                },
                'Date': '2013-01-23T19:30:00',
                'BodyHtml': '&lt;h3&gt;Title!&lt;/h3&gt;\r\n&lt;p&gt;Content!&lt;/p&gt;'
              }
            ]";
            IList<BlogPost> list = Common.JsonHelper.ArryJosn2List<BlogPost>(json);
            Console.WriteLine(list.Count);
            Console.WriteLine(list[0].Title);
           var list1= JsonConvert.DeserializeObject<List<BlogPost>>(json);
           Console.WriteLine(list1.Count);
           Console.WriteLine(list1[0].Title);
        }
        [TestMethod]
        public void DeserializeTest()
        {
            string json = @"{'Title': 'Json.NET is awesome!'}";
            var obj = Common.JsonHelper.Deserialize(json);
            Console.WriteLine(obj.Title);
        }
        #endregion
        #region StringHelperTest
        [TestMethod]
        public void GetMd5Test()
        {
            Console.WriteLine(Common.StringHelper.GetMd5("123456"));
        }
        [TestMethod]
        public void GetStrMaskTest()
        {
            Console.WriteLine(Common.StringHelper.GetStrMask("15789653654",4,3));
        }
        #endregion
        #region RegexHelperTest
        [TestMethod]
        public void ReplaceTest()
        {
           string result= Common.RegexHelper.Replace("18583986539",@"\d","*");
           Console.WriteLine(result);
           string result1 = Common.RegexHelper.Replace("18583986539", @"\d", "*",4,3);
           Console.WriteLine(result1);
        }
        #endregion
        #region DataTableHelperTest
        [TestMethod]
        public void Table2ListTest()
        {
           // DataTable
        }
        #endregion
        #region RandHelperTest
        [TestMethod]
        public void RandHelperTest()
        {
            Console.WriteLine(Common.RandHelper.GetRandLetter(6,1)+"---1");
            Console.WriteLine(Common.RandHelper.GetRandMix(6)+"---2");
            Console.WriteLine(Common.RandHelper.GetRandNubmer(6)+"---3");
        }
        #endregion
    }
    public class BlogPost
    {
        public string Title { get; set; }
        public string AuthorName { get; set; }
        public string AuthorTwitter { get; set; }
        public string Body { get; set; }
    }
}
